﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Brain
{
    public class InputFreeCamera3D : FreeCamera3D
    {
        public float Speed = 1;
        public Vector3 InitialRotationRadians;
        public Vector3 InitialPosition;

        public InputFreeCamera3D()
        {
        }
        public InputFreeCamera3D(GameScreen gs)
            : base(gs)
        {
        }

        public override void Draw()
        {
            IInputManager input = Engine.Instance.InputManager;
            Vector3 movementVector = Vector3.Zero;
            if (input.IsKeyDown(Keys.W))
            {
                movementVector += Vector3.Transform(Vector3.Forward, this.RotationMatrix);
            }
            if (input.IsKeyDown(Keys.S))
            {
                movementVector += Vector3.Transform(Vector3.Backward, this.RotationMatrix);
            }
            if (input.IsKeyDown(Keys.A))
            {
                movementVector += Vector3.Transform(Vector3.Left, this.RotationMatrix);
            }
            if (input.IsKeyDown(Keys.D))
            {
                movementVector += Vector3.Transform(Vector3.Right, this.RotationMatrix);
            }
            if (input.IsKeyDown(Keys.Q))
            {
                movementVector += Vector3.Transform(Vector3.Up, this.RotationMatrix);
            }
            if (input.IsKeyDown(Keys.Z))
            {
                movementVector += Vector3.Transform(Vector3.Down, this.RotationMatrix);
            }
            if (input.IsKeyDown(Keys.R))
            {
                this.Position = InitialPosition;
                this.RotationRadians = InitialRotationRadians;
            }
            this.Position += movementVector * Speed;

            if (input.IsMouseRightDown())
            {
                Vector2 dif = input.GetMouseDifference();
                this.DegreesRotation -= new Vector3(dif.X, dif.Y, 0);
            }

            base.Draw();
        }
    }
}
